package com.sicnu.comments.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sicnu.comments.entity.CommentsDO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface CommentMapper extends BaseMapper<CommentsDO> {

    @Select("SELECT * FROM comments WHERE resource_id = #{resourceId} AND parent_comment_id IS NULL ORDER BY created_at DESC")
    List<CommentsDO> selectTopLevelComments(@Param("resourceId") Integer resourceId);

    @Select("SELECT * FROM comments WHERE top_level_comment_id = #{topLevelCommentId} ORDER BY created_at ASC")
    List<CommentsDO> selectRepliesByTopLevelCommentId(@Param("topLevelCommentId") Integer topLevelCommentId);

    @Select("SELECT * FROM comments WHERE parent_comment_id = #{parentCommentId} ORDER BY created_at ASC")
    List<CommentsDO> selectRepliesByParentCommentId(@Param("parentCommentId") Integer parentCommentId);
}